package org.example.mppg.config;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import lombok.extern.slf4j.Slf4j;
import org.example.mppg.util.GeoJSONUtils;
import org.locationtech.jts.geom.Geometry;

import java.io.IOException;

/**
 * Geometry序列化为GeoJSON
 *
 * @description:
 * @author: bo
 * @create: 2024-09-25 11:32
 */
@Slf4j
public class GeometryToGeoJsonSerializer extends JsonSerializer<Geometry> {

    @Override
    public void serialize(Geometry value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
        if (value != null) {
            log.info("Geometry序列化-----打印日志------{}", value.getGeometryType());
            gen.writeObject(GeoJSONUtils.converGemToGeoJSON(value));
        }
    }
}
